package com.hb.common.controller;

import com.hb.common.dto.Database;
import com.hb.common.dto.DatabaseDto;
import com.hb.common.service.DatabaseService;
import com.hb.common.util.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据库
 */
@RestController
public class DatabaseController {

    @Resource
    private DatabaseService databaseService;

    /**
     * 获取数据库列表
     */
    @GetMapping("/db-backup/database")
    public Result<List<DatabaseDto>> selectDtoList() {
        return databaseService.selectDtoList();
    }

    /**
     * 获取数据库选择列表
     */
    @GetMapping("/db-backup/database/selection")
    public Result<List<DatabaseDto>> selectSelectionList(@RequestParam String dbType) {
        return databaseService.selectSelectionList(dbType);
    }

    /**
     * 保存数据库
     */
    @PostMapping("/db-backup/database")
    public Result<Boolean> save(@RequestBody Database database) {
        return databaseService.insertOrUpdate(database);
    }

    /**
     * 根据id获取数据库
     */
    @GetMapping("/db-backup/database/{id}")
    public Result<Database> getById(@PathVariable Integer id) {
        return databaseService.selectById(id);
    }

    /**
     * 删除数据库
     */
    @DeleteMapping("/db-backup/database")
    public Result<Boolean> delete(@RequestBody List<Integer> ids) {
        return databaseService.delete(ids);
    }

    /**
     * 更新数据库备份文件数量
     */
    @PostMapping("/db-backup/database/max-file-num")
    public Result<Boolean> updateFileCount(@RequestParam Integer id, @RequestParam Integer maxFileNum) {
        return databaseService.updateFileCount(id, maxFileNum);
    }

}
